﻿var grid = null;
$(function () {
    $("#txtDate").ligerDateEditor({
        showTime: false,
        format: "yyyy-MM-dd",
        width: 100,
        cancelable: false
    });

    var isDeptAll = 0;
    if ($("#hdnJobTitle").val().indexOf("护理部") > -1) isDeptAll = 1;
    $("#ddlDepartmentCode").ligerComboBox({
        cancelable: false,
        width: 120,
        url: "/Escort/EscortPersonnel/GetDepartmentList?isAll=" + isDeptAll + "&ram" + Math.random(),
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnDepartmentCode',
        value: $("#hdnJobTitle").val().indexOf("护理部") > -1 ? "-1" : $("#hdnCurrDepCode").val()
    });

    $("#ddlTiWenZhuangTai").ligerComboBox({
        cancelable: false,
        width: 120,
        data:
        [
            { text: '全部', id: '-1' },
            { text: '异常', id: '0' },
            { text: '正常', id: '1' }
        ],
        valueField: "id",
        textField: "text",
        valueFieldID: 'hdnTiWenZhuangTai',
        value: -1
    });
    $("#ddlShiFouXunCha").ligerComboBox({
        cancelable: false,
        width: 120,
        data:
        [
            { text: '全部', id: '-1' },
            { text: '是', id: '1' },
            { text: '否', id: '0' }
        ],
        valueField: "id",
        textField: "text",
        valueFieldID: 'hdnShiFouXunCha',
        value: -1
    });

    $('#btnSearch').click(function () {
        search();
    });

    $("#btnPrint").click(function () {
        var date = $("#txtDate").val();
        var depid = $("#hdnDepartmentCode").val();
        var temper = $("#hdnTiWenZhuangTai").val();
        var sfxc = $("#hdnShiFouXunCha").val();
        var url = "/Escort/TodayTrajectory/Export?date=" + date + "&depid=" + depid + "&temper=" + temper + "&sfxc=" + sfxc;
        Export(url);
    })
    $('#btnSearch').click();
});

//搜索
function search(pageNumber) {
    var queryData = {
        date: $("#txtDate").val(),
        departmentCode: $("#hdnDepartmentCode").val(),
        tiwenzhuangtai: $("#hdnTiWenZhuangTai").val(),
        sfxc: $("#hdnShiFouXunCha").val()
    }
    initTable(queryData, pageNumber);
}

var selectRow = false;

//加载列表
function initTable(queryData, pageNumber) {
    grid = $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Escort/TrajectoryHistory/Search?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: -5,
        columns: [
            { display: '床号', name: 'BED_NO', width: 80 },
            { display: '患者姓名', name: 'PATIENT_NAME', width: 80 },
            { display: '病区', name: 'NURSE_CELL_NAME', width: 100 },
            { display: '陪护人名称', name: 'ESCORT_NAME', width: 80 },
            { display: '年龄', name: 'ESCORT_AGE', width: 80 },
            { display: '性别', name: 'ESCORT_SEX_NAME', width: 80 },
            { display: '陪护联系方式', name: 'ESCORT_PHONE', width: 100 },
            { display: '时间', name: 'CREATED_DT_NAME', width: 80 },
            {
                display: '体温值', name: 'TEMPERATURE', width: 80,
                render: function (rowData) {
                    if (rowData.TEMPERATURE == null) return "";
                    if (parseFloat(rowData.TEMPERATURE) >= parseFloat(default_temper_line))
                        return "<span style=\"color:red\">" + rowData.TEMPERATURE + "</span>";
                    return rowData.TEMPERATURE;
                }
            },
            { display: '是否巡查', name: 'PATROL_FLAG_NAME', width: 80 },
            { display: '个人防护设备', name: 'PROTECT_FLAG_NAME', width: 80 },
            { display: '防护内容', name: 'PROTECT_TEXT', width: 80 },
            { display: '呼吸道症状', name: 'BREATH_FLAG_NAME', width: 80 },
            { display: '呼吸症状内容', name: 'BREATH_TEXT ', width: 80 },
            { display: '消化症状', name: 'DIGESTION_FLAG_NAME', width: 80 },
            { display: '消化症状内容', name: 'DIGESTION_TEXT ', width: 80 }
        ],
        onSuccess: function (data, grid) {
        }, onSelectRow: function (rowdata, rowindex) {
            if (selectRow) return;
            selectRow = true;
            var esid = rowdata.ESCORT_ID;
            var date = $("#txtDate").val();
            var url = "/Escort/TodayTrajectory/GetEscortPathInfo";
            $.ajax({
                url: url,
                type: "POST",
                cache: false,
                data: { esid: esid, date: date },
                success: function (data) {
                    selectRow = false;
                    var d = $.parseJSON(data);
                    var strHtml = "<li class=\"first\">&nbsp;&nbsp;&nbsp;" + rowdata.ESCORT_NAME + "今日轨迹</li>";
                    for (var i = 0; i < d.length; i++) {
                        var time = d[i].CREATED_DT.toString().split(' ', 2)[1].toString();
                        var hh = time.split(":", 2)[0];
                        var mm = time.split(":", 2)[1];
                        var title = d[i].IO_FLAG_NAME;
                        strHtml += "<li class=\"time\"><img src=\"/content/images/icon_blue.png\">&nbsp;&nbsp;&nbsp;&nbsp;" + hh + ":" + mm + " " + title + "</li>";
                    }
                    //<li class="time"><img src="/content/images/icon_blue.png">&nbsp;&nbsp;20:00 进入医院</li>
                    $(".div_guiji ul").html("");
                    $(".div_guiji ul").html(strHtml);
                },
                error: function () {
                    selectRow = false;
                    $.ligerDialog.error("程序错误");
                }
            });

        }
    });
    GridNoData($("#maingrid"));
}